﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb
{
    public partial class buyer_budgetList :buyerPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("ED", 1))
                {
                    drpBind();
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "buyer_index.html");
                    return;
                }
            }
        }
        void drpBind()
        {
            int byear = DateTime.Now.Year;
            int bmonth = DateTime.Now.Month + 1;
            for (int i = 2010; i <= 2015; i++)
            {
                ddl_Byear.Items.Add(i.ToString());
            }
            for (int i = 0; i < ddl_Byear.Items.Count; i++)
            {
                if (ddl_Byear.Items[i].Value == byear.ToString())
                {
                    ddl_Byear.Items[i].Selected = true;
                }
            }
            for (int i = 1; i <=12; i++)
            {
                ddl_Bmonth.Items.Add(i.ToString());
            }
            ddl_Bmonth.Items.Insert(0, new System.Web.UI.WebControls.ListItem("-请选择-", ""));
            //for (int i = 0; i < ddl_Bmonth.Items.Count; i++)
            //{
            //    if (ddl_Bmonth.Items[i].Value == bmonth.ToString())
            //    {
            //        ddl_Bmonth.Items[i].Selected = true;
            //    }
            //}
        }
        void rptBind()
        {
            int companyid = logic.customer.getCompanyId();
            StringBuilder where = new StringBuilder();
            where.Append("CompanyId=" + companyid+" and Byear="+Convert.ToInt32(ddl_Byear.SelectedValue));
            if (ddl_Bmonth.SelectedValue.Trim() != "")
                where.AppendFormat(" and [Bmonth] ={0}", ddl_Bmonth.SelectedValue.Trim());
            DataSet ds = logic.buyBudget.select(where.ToString(), "Bid desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void btn_select_Click(object sender, EventArgs e)
        {
            rptBind();
        }

        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "IsHint")
            {
                int bid = Convert.ToInt32(e.CommandArgument);
                logic.buyBudget.updateIsHint(bid);
                rptBind();
            }
        }
    }
}
